<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<meta charset="text/html; charset=utf-8"/>
<head th:insert="~{common/common::head-fragment('管理界面')}">
</head>
<body>
<div th:insert="~{common/common::header-fragment}"></div>

<div class="layui-container">

        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <a th:href="@{/getBannedUser}"><li>用户</li></a>
                <li class="layui-this">文章</li>
                <span class="fly-search" style="float: right; padding-top: 15px"><i class="layui-icon"></i></span>
            </ul>
        </div>

</div>
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="fly-panel" style="margin-bottom: 0;">
                <!-- 2.渲染帖子分页列表数据 -->
                <th:block th:if="${#lists.isEmpty(pageResult.list)}">
                    <!-- 无数据时 -->
                    <div class="fly-none">没相关数据</div>
                </th:block>
                <th:block th:unless="${#lists.isEmpty(pageResult.list)}">
                    <ul class="fly-list">
                        <th:block th:each="myPostListEntity : ${pageResult.list}">
                            <li>
                                <a th:href="@{${'/userCenter/'+myPostListEntity.publishUserId}}" class="fly-avatar">
                                    <img th:src="@{${myPostListEntity.headImgUrl}}"
                                         th:alt="${myPostListEntity.nickName}">
                                </a>
                                <h2>
                                    <a href="##" class="layui-badge"
                                       th:text="${myPostListEntity.postCategoryName}">分享</a>
                                    <a th:href="@{${'/detail/'+myPostListEntity.postId}}"
                                       th:text="${myPostListEntity.postTitle}">嘿嘿嘿</a>
                                </h2>
                                <div class="fly-list-info">
                                    <a th:href="@{${'/userCenter/'+myPostListEntity.publishUserId}}" link>
                                        <cite th:text="${myPostListEntity.nickName}">程序员</cite>
                                    </a>
                                    <span th:text="${#dates.format(myPostListEntity.createTime, 'yyyy-MM-dd HH:mm:ss')}">刚刚</span>
                                    <span class="fly-list-kiss layui-hide-xs" title="赞">
                                        <i class="iconfont icon-zan"></i>
                                        <th:block th:text="${myPostListEntity.postCollects}"></th:block>
                                    </span>
                                    <span class="fly-list-nums" style="right: 100px">
                                        <i class="iconfont icon-pinglun1" title="标题"></i>
                                        <th:block th:text="${myPostListEntity.postComments}"></th:block>
                                    </span>
                                    <span th:if="${myPostListEntity.postStatus ne 1}" class="fly-list-nums" style="float: right;">
                                        <a class="layui-btn layui-btn-xs jie-admin" th:onclick="|unBannedPost(${myPostListEntity.postId})|">解封</a>
                                    </span>
                                    <span th:if="${myPostListEntity.postStatus eq 1}" class="fly-list-nums" style="float: right;">
                                        <a class="layui-btn layui-btn-xs jie-admin" th:onclick="|bannedPost(${myPostListEntity.postId})|">封禁</a>
                                    </span>
                                </div>
                                <div class="fly-list-badge">
                                </div>
                            </li>
                        </th:block>
                    </ul>
                    <div style="text-align: center">
                        <div class="laypage-main">
                            <th:block th:if="${pageResult.currPage>1}">
                                <a class="laypage-prev"
                                   th:href="@{/getBannedPost(page=${pageResult.currPage-1}, keyword=${keyword})}">
                                    &lt;&lt;</a>
                            </th:block>
                            <th:block th:if="${pageResult.currPage==1}">
                                <a class="laypage-prev"
                                   href="##">
                                    &lt;&lt;</a>
                            </th:block>
                            <th:block th:if="${pageResult.currPage-2 >=1}">
                                <a class="laypage-prev"
                                   th:href="@{/getBannedPost(page=${pageResult.currPage-2}, keyword=${keyword})}"
                                   th:text="${pageResult.currPage - 2}">1</a>
                            </th:block>
                            <th:block th:if="${pageResult.currPage-1 >=1}">
                                <a class="laypage-prev"
                                   th:href="@{/getBannedPost(page=${pageResult.currPage-1}, keyword=${keyword})}"
                                   th:text="${pageResult.currPage - 1}">1</a>
                            </th:block>
                            <a href="##" class="laypage-curr" th:text="${pageResult.currPage}">1</a>
                            <th:block th:if="${pageResult.currPage+1<=pageResult.totalPage}">
                                <a class="laypage-next"
                                   th:href="@{/getBannedPost(page=${pageResult.currPage+1}, keyword=${keyword})}"
                                   th:text="${pageResult.currPage + 1}">1</a>
                            </th:block>
                            <th:block th:if="${pageResult.currPage+2<=pageResult.totalPage}">
                                <a class="laypage-next"
                                   th:href="@{/getBannedPost(page=${pageResult.currPage+2}, keyword=${keyword})}"
                                   th:text="${pageResult.currPage + 2}">1</a>
                            </th:block>
                            <th:block th:if="${pageResult.currPage<pageResult.totalPage}">
                                <a class="laypage-next"
                                   th:href="@{/getBannedPost(page=${pageResult.currPage+1}, keyword=${keyword})}">
                                    &gt;&gt;</a>
                            </th:block>
                            <th:block th:if="${pageResult.currPage==pageResult.totalPage}">
                                <a class="laypage-next" href="##">&gt;&gt;</a>
                            </th:block>
                        </div>
                    </div>
                </th:block>
            </div>
        </div>
    </div>
    <div id="unBannedPostInfo" style="display: none; text-align: center">
        <div style="text-align: center;vertical-align: middle; flex: content"  class="layui-input-inline">
            <p style="text-align: center">确定要解封此文章吗?</p>
        </div>
    </div>
    <div id="bannedPostInfo" style="display: none; text-align: center">
        <div style="text-align: center;vertical-align: middle; flex: content"  class="layui-input-inline">
            <p style="text-align: center">确定要封禁此文章吗?</p>
        </div>
    </div>
</div>

<div th:insert="~{common/common::footer}"></div>

<script th:src="@{/js/public.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<!-- wangEditor -->
<script type="text/javascript" th:src="@{/js/wangeditor/wangEditor.min.js}"></script>

<script type="text/javascript">
    layui.use(['layer', 'element', 'jquery', 'form'], function () {
        var layer = layui.layer, $ = layui.$, element = layui.element, form = layui.form;

        // 解封
        window.unBannedPost = function (postId){
            layer.open({
                type: 1
                , title: false
                , closeBtn: false
                , area: ['300px', '100px']
                , shade: 0.8
                , id: 'LAY_layuipro'
                , btn: ['确定', '取消']
                , btnAlign: 'c'
                , moveType: 1
                , content: $("#unBannedPostInfo")
                , yes: () => {
                    let params = {
                        'postId': postId,
                    };
                    $.ajax({
                        type: "POST",
                        url: "/postUnBanned",
                        data: params,
                        async: false,
                        success: function (result) {
                            if (result.resultCode === 200) {
                                layer.msg("解封成功");
                            } else {
                                layer.msg(result.message);
                            }
                        },
                        error: function () {
                            layer.alert('操作失败!', {title: '提醒', skin: 'layui-layer-molv', icon: 2});
                        }
                    });

                    window.setTimeout(function () {
                        window.location.href = "/getBannedPost";
                    },700)
                }
            })
        };

        // 封禁
        window.bannedPost = function (postId){
            layer.open({
                type: 1
                , title: false
                , closeBtn: false
                , area: ['300px', '100px']
                , shade: 0.8
                , id: 'LAY_layuipro'
                , btn: ['确定', '取消']
                , btnAlign: 'c'
                , moveType: 1
                , content: $("#bannedPostInfo")
                , yes: () => {
                    let params = {
                        'postId': postId,
                    };
                    $.ajax({
                        type: "POST",
                        url: "/postBanned",
                        data: params,
                        async: false,
                        success: function (result) {
                            if (result.resultCode === 200) {
                                layer.msg("封禁成功");
                            } else {
                                layer.msg(result.message);
                            }
                        },
                        error: function () {
                            layer.alert('操作失败!', {title: '提醒', skin: 'layui-layer-molv', icon: 2});
                        }
                    });

                    window.setTimeout(function () {
                        window.location.href = "/getBannedPost";
                    },700)
                }
            })
        };

        // toUser
        window.toUserBlackHome = function (){
            $.ajax({
                type: 'GET',
                url: '/getBannedUser',
            })
        }

        //搜索
        $('.fly-search').on('click', function () {
            layer.open({
                type: 1
                , title: false
                , closeBtn: false
                //,shade: [0.1, '#fff']
                , shadeClose: true
                , maxWidth: 10000
                , skin: 'fly-layer-search'
                , content: ['<form action="/getBannedPost">'
                    , '<input autocomplete="off" placeholder="标题搜索，回车跳转" type="text" name="keyword">'
                    , '</form>'].join('')
                , success: function (layero) {
                    var input = layero.find('input');
                    input.focus();
                    layero.find('form').submit(function () {
                        var val = input.val();
                        if (val.replace(/\s/g, '') === '') {
                            return false;
                        }
                        input.val(input.val());
                    });
                }
            })
        });
    });
</script>
</body>
</html>